package recycleTest 
{
	import asunit.asserts.*;
	import util.boyaa.DataStructure.list.DoubleNode;
	
	
	/**
	 * ...
	 * @author henrylee   Any question, pls contact me. henrylee_sz@qq.com.
	 */
	public final class DoubleListTest 
	{
		private var doubleList: DoubleNode;
		
		[Before]
		public function initialize():void
		{
			doubleList = new DoubleNode(1);
		}

		[After]
		public function tearDown():void
		{
			if (doubleList != null) {
				var _prev: DoubleNode;
				while (doubleList.next != null) {
					_prev = doubleList;
					doubleList = doubleList.next;
					_prev.unlink();
				}
				doubleList.unlink();
			}
		}
		
		[Test]
		public function addNode():void
		{
			doubleList.addAfter(new DoubleNode(2));
			assertEquals(2, doubleList.nodeLength);
			doubleList.addAfter(new DoubleNode(3));
			doubleList.addAfter(new DoubleNode(4));
			doubleList.addAfter(new DoubleNode(5));
			doubleList.addAfter(new DoubleNode(6));
			assertEquals(6, doubleList.nodeLength);
			
			var cursor:DoubleNode;
			var i: int = 6;
			for (cursor = doubleList; cursor != null; cursor = cursor.next) {
				assertEquals(i--, cursor.nodeLength);
			}
			
			for (cursor = doubleList; cursor != null; cursor = cursor.next) {
				if (cursor.nodeData == 3 || cursor.nodeData == 5) cursor.unlink();
				if (cursor.nodeData == 4) cursor.addAfter(new DoubleNode(7));
			}
			assertEquals(5, doubleList.nodeLength);
		}
		
	}

}